package com.controller;

import com.controller.vo.ResultVO;
import com.service.LikeInfoService;
import com.service.TaskMonitorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ClassName: PostLikeController
 * Description:
 *
 * @author L_Z_R
 * @version 1.0
 * @create 2025/05/23 08:51
 */
@RestController
public class PostLikeController extends BaseController{
    @Autowired
    private LikeInfoService likeInfoService;
    @Autowired
    private TaskMonitorService taskMonitorService;

    @PostMapping("/addLike")
    public ResultVO<String> addLike(@RequestParam("accountId") Integer accountId,@RequestParam("postId") Integer postId){
        likeInfoService.addLike(accountId,postId);
        taskMonitorService.checkAndRewardTask(accountId, (byte)4);
        return success("点赞成功");
    }

    @PostMapping("/removeLike")
    public ResultVO<String> removeLike(@RequestParam("accountId") Integer accountId,@RequestParam("postId") Integer postId){
        likeInfoService.removeLike(accountId,postId);
        return success("取消点赞成功");
    }

    /**
     * 获取帖子点赞数
     * @param postId 帖子id
     * @return 点赞数
     */
    @GetMapping("/getLikeCount")
    public ResultVO<Integer> getLikeCountByPostId(@RequestParam("postId") Integer postId){
        Integer likeCount = likeInfoService.getLikeCountByPostId(postId);
        return success(likeCount);
    }

    @PostMapping("/addCommentLike")
    public ResultVO<String> addCommentLike(@RequestParam("accountId") Integer accountId,@RequestParam("commentId") Integer commentId){
        likeInfoService.addCommentLike(accountId,commentId);
        taskMonitorService.checkAndRewardTask(accountId, (byte)4);
        return success("点赞评论成功");
    }

    @PostMapping("/removeCommentLike")
    public ResultVO<String> removeCommentLike(@RequestParam("accountId") Integer accountId,@RequestParam("commentId") Integer commentId){
        likeInfoService.removeCommentLike(accountId,commentId);
        return success("取消点赞评论成功");
    }
}
